/**
 * http://usejsdoc.org/
 */
var http = require('http'),  //服务器创建
    url = require('url'),    //url处理
    fs = require('fs'),		 //文件操作
    jade = require('jade'),
    router = require('./router.js'); //路由加载

http.createServer(function(req, res) {
	res.render = function(){
		var template = arguments[0];
		var options = arguments[1];
		var str = fs.readFileSync(template,'utf8');
		var fn = jade.compile(str,{filename:template,pretty:true});
		
		var page = fn(options);
		res.writeHeader(200,{'Content-Type':'text/html'});
		res.end(page);
	};
	req.setEncoding('UTF-8');
	router.router(res, req);
}).listen(8080);

console.log("Sever Starting...");